package com.version1_4.controller;

import com.alibaba.fastjson.JSONObject;
import com.version1_3.controller.ActivityController;
import com.version1_3_1.controller.ActivityController1_3_1;
import com.version1_4.service.ActivityService1_4;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by reeveslee on 16/4/27.
 */
@Controller
public class ActivityController1_4 {
    private static final Logger LOGGER = Logger.getLogger(ActivityController1_4.class);

    @Autowired
    private ActivityController activityController;

    @Autowired
    private ActivityController1_3_1 activityController131;

    @Autowired
    private ActivityService1_4 activityService14;

    /*    之前版本接口     */

    /**
     * 活动主界面
     */
    @RequestMapping(value = "/version1_4/activity/main/{userId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String activityMainPage(@PathVariable("userId") int userId) {
        return activityService14.activityMainPage(userId);
    }

    /**
     * 活动详情页面
     */
    @RequestMapping(value = "/version1_4/activity/activityInfo/{activityId}", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String activityInfo(@PathVariable("activityId") int activityId) {
        return activityService14.activityInfo(activityId);
    }

    /**
     * 我的活动
     */
    @RequestMapping(value = "/version1_4/activity/myActivity/{userId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String myActivity(@PathVariable("userId") int userId) {
        return activityController.myActivity(userId);
    }


    /**
     * 参与活动
     */
    @RequestMapping(value = "/version1_4/activity/joinActivity/{userId}/{activityId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String joinActivity(@PathVariable("userId") int userId, @PathVariable("activityId") int activityId) {
        return activityController.joinActivity(userId, activityId);
    }

    /**
     * 活动打卡界面
     */
    @RequestMapping(value = "/version1_4/activity/activityPage/{activityId}/{userId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String activityPage(@PathVariable("activityId") int activityId, @PathVariable("userId") int userId) {
        return activityController131.activityPage(activityId, userId);
    }

    /**
     * 打卡
     */
    @RequestMapping(value = "/version1_4/activity/launch", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String launchActivity(@RequestBody JSONObject jsonObject) {
        return activityController131.launchActivity(jsonObject);
    }

    /**
     * 分享打卡信息
     */
    @RequestMapping(value = "/version1_4/activity/shareLauchCardInfo/{activityId}/{userId}", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView shareLauchCardInfo(@PathVariable("activityId") int activityId, @PathVariable("userId") int userId) {
        return activityController.shareLauchCardInfo(activityId, userId);
    }

    /**
     * 记录用户分享打卡信息积分
     */
    @RequestMapping(value = "/version1_4/activity/recordShareLaunchCardInfo/{activityId}/{userId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String recordShareLaunchCardInfo(@PathVariable("activityId") int activityId, @PathVariable("userId") int userId) {
        return activityController.recordShareLaunchCardInfo(activityId, userId);
    }

    /**
     * 设置用户身高体重信息
     */
    @RequestMapping(value = "/version1_4/activity/setBodyInfo", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String setUserBodyInfo(@RequestBody JSONObject jsonObject) {
        return activityController.setUserBodyInfo(jsonObject);
    }

    /**
     * 跬步公益跑输入里程
     */
    @RequestMapping(value = "/version1_4/version1_3_1/activity/inputMile/{mile}/{userId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String inputMile(@PathVariable("mile") double mile, @PathVariable("userId") int userId) {
        return activityController131.inputMile(mile, userId);
    }
}
